import BaseController from "../../cfw/mvc/BaseController";
import ModuleManager, { ModuleID } from "../../cfw/module/ModuleManager";
import { UIIndex } from "../../cfw/tools/Define";
import LobbyController from "../lobby/LobbyController";
import EnterGameLoading from "./EnterGameLoading";
import HouseController from "../decoration/HouseController";
import CookeryController from "../cookery/CookeryController";
import GiftC from "../gift/GiftC";
import CrazyClickC from "../crazyClick/CrazyClickC";
import RedPacketC from "../../sdk/redpacket/RedPacketC";
import FloatC from "../float/FloatC";

export default class LoadingController extends BaseController {

    private static ins: LoadingController;

    static instance() {
        if (!this.ins) {
            this.ins = new LoadingController()
        }
        return this.ins;
    }

    private nextModule: number = ModuleID.LOBBY;

    private cache: number[] = []
    intoLayer(nextModule: ModuleID, list: number[]) {
        this.nextModule = nextModule;
        if (this.cache[this.nextModule]) {
            this.next()
        } else {
            this.pushView('prefabs/LoadingView', 'LoadingView', new EnterGameLoading(list), ModuleManager.getLoader(ModuleID.LOADING), UIIndex.ROOT)
        }

    }

    next() {
        cc.log(' next ===========  ', this.nextModule)
        this.cache[this.nextModule] = 1;
        switch (this.nextModule) {
            case ModuleID.LOBBY:
                LobbyController.instance().intoLayer()
                FloatC.instance().intoLayer()
                RedPacketC.instance().showFriend()
                if (ModuleManager.publicAudio().getMusicFlag()) {
                    ModuleManager.publicAudio().playMusic('audio/cartoon-time')
                }
                break;
            case ModuleID.COOKIE:
                CookeryController.instance().intoLayer()
                break;
            case ModuleID.OUT_DOOR:
                HouseController.instance().intoLayer()
                break;
            case ModuleID.GIFT:
                GiftC.instance().intoLayer()
                break;
            case ModuleID.CRAZY_CLICK:
                CrazyClickC.instance().intoLayer()
                break;
        }

    }
}
